Skip to content

Honor HTTP/1.1 persistent-connection default per RFC 9112 §9.3#209

Merged
swhitty merged 1 commit into
swhitty:mainfrom
ianegordon:ian/tvt-288-http11-keep-alive-default
Apr 26, 2026
Merged

Honor HTTP/1.1 persistent-connection default per RFC 9112 §9.3#209
swhitty merged 1 commit into
swhitty:mainfrom
ianegordon:ian/tvt-288-http11-keep-alive-default

Conversation

@ianegordon

Copy link
Copy Markdown
Contributor

Summary

  • HTTPRequest.shouldKeepAlive now follows RFC 9112 §9.3: HTTP/1.1 connections persist unless Connection: close; HTTP/1.0 connections close unless Connection: keep-alive is present. The Connection header is split on commas so multi-token values like Keep-Alive, Upgrade are handled (RFC 9110 §7.6.1).
  • HTTPServer.handleRequest no longer overwrites a Connection header that the handler explicitly set (e.g. WebSocket's Upgrade). It only echoes the request's Connection token when the response has none.
  • Previously, an HTTP/1.1 client that omitted Connection: keep-alive (the compliant default) would have the connection closed after one request. With multi-token headers, even Keep-Alive, Upgrade failed the equality check.

Closes TVT-288.

Test plan

  • Add 9 HTTPRequestTests cases covering HTTP/1.1 default, multi-token, and HTTP/1.0 semantics.
  • Update connectionRequestsAreReceived_WhileConnectionIsKeptAlive to terminate via Connection: close instead of relying on the previous (buggy) behavior.
  • Full suite: 417 tests, 49 suites, all passing locally.

HTTPRequest.shouldKeepAlive now treats HTTP/1.1 as persistent unless
`Connection: close` is sent, and HTTP/1.0 as closed unless `keep-alive`
is sent. Splits the Connection header on commas so multi-token values
like `Keep-Alive, Upgrade` are recognized (RFC 9110 §7.6.1).

HTTPServer.handleRequest no longer overwrites a Connection header that
the handler explicitly set (e.g. WebSocket's `Upgrade`); it only echoes
the request's Connection token when the response has none.

Adds nine HTTPRequest.shouldKeepAlive cases covering HTTP/1.1 default,
multi-token, and HTTP/1.0 semantics. Updates the keep-alive iteration
test to terminate via `Connection: close` instead of relying on the
old (buggy) behavior.

Closes TVT-288

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@codecov

codecov Bot commented Apr 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.69%. Comparing base (4a8c239) to head (978bd49).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #209      +/-   ##
==========================================
+ Coverage   92.67%   92.69%   +0.01%     
==========================================
  Files          69       69              
  Lines        3551     3558       +7     
==========================================
+ Hits         3291     3298       +7     
  Misses        260      260              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@swhitty swhitty merged commit 4fcb6c3 into swhitty:main Apr 26, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants